﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vhcs.Data.Dto;
using System.Data;
using Vhcs.Data.Shared;

namespace Vhcs.Data.Dao
{
    public class CommentDao
    {

        public void InsertComment(CommentDTO com)
        {
            string StoreName = @"COM_spK2Approve_Insert";

            object[] parms = Take(com);
            Db.InsertFromStore(StoreName, parms);
        }

        /// <summary>
        /// Get Data from CommentDTO
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        private object[] Take(CommentDTO com)
        {
            return new object[]  
            {
               "@ID", com.Id
               ,"@note", com.note
               ,"@position", com.position
               ,"@role", com.role
               ,"@signdate", com.signdate
               ,"@signer", com.signer
               ,"@Type", com.Type
               ,"@status", com.status};
        }

        /// <summary>
        /// Create comment object
        /// </summary>
        private Func<IDataReader, CommentDTO> Make = reader =>
            new CommentDTO
            {
                Id = reader["Id"].AsInt(),
                note = reader["note"].AsString(),
                position = reader["position"].AsString(),
                role = reader["role"].AsInt(),
                signdate = reader["signdate"].AsDateTime(),
                signer = reader["signer"].AsString(),
                Type = reader["Type"].AsShort(),
                status = reader["status"].AsString()
            };
    }
}
